package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.CollectiveSalesTimePoints;
import com.sc.nft.mapper.CollectiveSalesTimePointsMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_collective_sales_time_points)数据DAO
 *
 * @author zxy
 * @since 2024-09-16 17:11:23
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class CollectiveSalesTimePointsDao extends ServiceImpl<CollectiveSalesTimePointsMapper, CollectiveSalesTimePoints> {

    public void clearByCollectiveId(Long collectiveId) {
        LambdaUpdateWrapper<CollectiveSalesTimePoints> wrapper = new LambdaUpdateWrapper<CollectiveSalesTimePoints>();
        wrapper.eq(CollectiveSalesTimePoints::getCollectiveId, collectiveId);
        remove(wrapper);
    }
    public List<CollectiveSalesTimePoints> findByCollectiveId(Long collectiveId) {
        return lambdaQuery().eq(CollectiveSalesTimePoints::getCollectiveId, collectiveId).orderByAsc(CollectiveSalesTimePoints::getTimePoint).list();
    }

    public CollectiveSalesTimePoints getNowPrice(Long collectiveId) {
        return lambdaQuery().eq(CollectiveSalesTimePoints::getCollectiveId, collectiveId).last(" and time_point <= CURTIME() order by time_point desc limit 1 ").one();
    }
}